package main

import "fmt"

func main() {
	fn1()
	fn2()
	fn3()
	fmt.Println(fn4(10, 0))
}
func fn1() {
	fmt.Println("开始")
}
func fn2() {
	defer func() {
		i := recover() //获取到异常
		if i != nil {  //判断是否有异常
			fmt.Println(i)
		}
	}()
	panic("抛出一个异常")

}

func fn3() {
	fmt.Println("结束")
}
func fn4(a int, b int) int {
	defer func() {
		err := recover()
		if err != nil {
			fmt.Println("error", err)
		}
	}()
	return a / b
}
